<template>
  <!-- 宽高必须指定 雷达图的基础渲染 -->
  <div ref="charts" class="box" />
</template>

<script>
import * as echarts from 'echarts'

export default {
  props: {
    indicator: {
      type: Array,
      default: () => []
    }
  },
  // 监听到变化 立即修改echart的配置项 影响echart视图
  watch: {
    indicator() {
      this.myChart.setOption({
        ...this.option,
        radar: {
          // shape: 'circle',
          indicator: this.indicator
        }
      })
    }
  },
  mounted () {
    this.charts()
  },
  methods: {
    charts() {
      this.myChart = echarts.init(this.$refs.charts)

      this.option = {

        radar: {
          // shape: 'circle',
          indicator: this.indicator
        },
        series: [
          {
            name: 'Budget vs spending',
            type: 'radar',
            data: [
              {
                value: [4200, 3000, 20000, 35000, 50000, 18000],
                name: 'Allocated Budget'
              },
              {
                value: [5000, 14000, 28000, 26000, 42000, 21000],
                name: 'Actual Spending'
              }
            ]
          }
        ]
      }

      this.option && this.myChart.setOption(this.option)
    }
  }
}
</script>

<style lang="scss" scoped>
.box{
  width: 400px;
  height: 300px;
}
</style>
